package pm;
import java.util.Random;
/*
* 编写双色球程序
1、编写一个方法，随机生成一注双色球。（规则请自行百度）
2、编写测试程序，随机生成一注双色球，为开奖号码
3、编写模拟彩票站机选程序，使用循环不断生成机选号码，直到号码与一等奖号码一致位置，
* 输出运行了多少次的次数，次数*2位买彩票金额数。*/
public class Homework {
    //一等奖的号码数组
    private int[] qiu=new int[7];
    //我的数组
    private int[] qiu1=new int[7];

    //生成中将号码的方法
    public void jiang() {
        int count = 0;//数组下标
        boolean flag=true;
        //循环计算红球号码
        while (count<6) {
            qiu[count] = new Random().nextInt(7) + 1;
            boolean flag1=true;
            //遍历数组判断是否重复
            for (int j = 0; j <= 5; j++) {
                if (qiu[count] == qiu[j] && (count!=j)) {
                    //System.out.println("红球号码重复");
                    flag1=false;
                    break;
                }
            }
            //不重复则下标加一，进行下一个元素的输入,否则继续添加
            if(flag1==true){
                count++;
            }
        }
        //蓝球中奖号码
        qiu[6] = new Random().nextInt(1) + 1;

        System.out.println();
    }

    public void me(){
        int count = 0;
        boolean flag=true;
        while (count<6) {
            qiu1[count] = new Random().nextInt(7) + 1;
            boolean flag1=true;
            for (int j = 0; j <= 5; j++) {
                if (qiu1[count] == qiu1[j] && (count!=j)) {
                    //System.out.println("红球号码重复");
                    flag1=false;
                    break;
                }
            }
            if(flag1==true){
                count++;
            }
        }
        qiu1[6] = new Random().nextInt(1) + 1;

        System.out.println();
    }

    public static void main(String[] args) {
        Homework homework=new Homework();
        int person=0;//计算第几人中奖
        boolean flag1=true;
        while(flag1){
            homework.jiang();
            homework.me();
            boolean flag=true;
            for(int i=0;i<7;i++){
                if(homework.qiu[i]!=homework.qiu1[i]){
                    //System.out.println("你没有中奖");
                    flag=false;
                    break;
                }
            }
            if(flag==true){
                System.out.print("中将号码:");
                for (int i = 0; i < homework.qiu.length; i++) {
                    System.out.print(homework.qiu[i]+" ");
                }
                System.out.println();
                System.out.print("我的号码:");
                for (int i = 0; i < homework.qiu1.length; i++) {
                    System.out.print(homework.qiu1[i]+" ");
                }
                System.out.println();
                System.out.println("恭喜你中奖了");
                flag1=false;
            }
            person++;
        }
        System.out.println("第"+person+"人中将，花了"+(person*2)+"钱买双色球");
    }
}
